package com.xgry.bpm.api.base.tableclass.service.impl;

import com.xgry.bpm.api.base.tableclass.entity.TableClass;
import com.xgry.bpm.api.base.tableclass.mapper.TableClassMapper;
import com.xgry.bpm.api.base.tableclass.service.TableClassService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.apache.http.HttpStatus;

import java.util.List;

/**
* <p>
    * TableClass服务实现类
    * </p>
*
* @author adrian
* @since 2020-07-07
*/
@Service
public class TableClassServiceImpl extends ServiceImpl<TableClassMapper, TableClass>implements TableClassService {

    @Override
    public int deleteById(String id){
        if(StringUtils.isEmpty(id)){
            throw new IllegalArgumentException(String.valueOf(HttpStatus.SC_METHOD_FAILURE));
        }
        return baseMapper.deleteById(id);
    }

    @Override
    public TableClass selectById(String id){
        if(StringUtils.isEmpty(id)){
            throw new IllegalArgumentException(String.valueOf(HttpStatus.SC_METHOD_FAILURE));
        }
        TableClass data=baseMapper.selectById(id);
        return data;
    }

    @Override
    public List<TableClass>selectAll(TableClass record){
        QueryWrapper<TableClass>queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(record);
        List<TableClass>list=baseMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public IPage<TableClass>selectPage(IPage<TableClass> page , TableClass record){
        // 查询条件
        QueryWrapper<TableClass>queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(record);
        return baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public IPage<TableClass>getPage(IPage<TableClass>page,QueryWrapper<TableClass>queryWrapper){
        return baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public List<TableClass> findByTableNameList(String tableClassName) {
        return  baseMapper.selectList(new QueryWrapper<TableClass>(){{
            this.eq("tableClassName",tableClassName);
        }});
    }

    @Override
    public TableClass findByTableClassName(String cTableName) {
        List<TableClass> tableClassName = baseMapper.selectList(new QueryWrapper<TableClass>() {{
            this.eq("tableClassName", cTableName);
        }});
        return CollectionUtils.isEmpty(tableClassName)?null:tableClassName.get(0);
    }

    @Override
    public List<TableClass> findBytableClassIdP(Integer tableClassId) {
        return baseMapper.selectList(new QueryWrapper<TableClass>() {{
            this.eq("pid", tableClassId);
        }});
    }

    @Override
    public List<TableClass> findByModelId(Integer modelId) {
        return baseMapper.selectList(new QueryWrapper<TableClass>() {{
            this.eq("modelId", modelId);
        }});
    }
}